package com.example.campusproject.slice;

import  com.example.campusproject.ResourceTable;
import com.example.campusproject.adapter.YWNNListAdapter;
import com.example.campusproject.entity.YWNN;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Component;
import ohos.agp.components.ListContainer;
import ohos.ivihardware.advancedmanager.IntNoZoneSubscribeCallback;

import java.util.ArrayList;
import java.util.List;

public class YWNNAbilitySlice extends AbilitySlice {
    private ListContainer lc_list;
    private int[] images={
            ResourceTable.Media_huaqingchi,
            ResourceTable.Media_dayanta,
            ResourceTable.Media_bingmayong,
            ResourceTable.Media_lishan,
            ResourceTable.Media_datangfurongyuan,
            ResourceTable.Media_zhonglou
    };
    private String[] names = new String[] { "华清池", "大雁塔", "兵马俑", "骊山", "大唐芙蓉园",
            "钟楼" };
    private String[] briefs = new String[] { "唐代华清宫", "大雁塔作为现存最早、规模最大的唐代四方楼阁式砖塔",
            "第一批中国世界遗产", "中华民族历史脉络的见证", "陕西省西安市5A级旅游景区", "中国现存钟楼中形制最大、保存最完整的一座" };
    private List<YWNN> ywnns=new ArrayList<>();
    private YWNNListAdapter adapter;
    @Override
    protected void onStart(Intent intent) {
        super.onStart(intent);
        this.setUIContent(ResourceTable.Layout_ability_ywnn);
        lc_list= (ListContainer) this.findComponentById(ResourceTable.Id_lc_list);
        initDate();
        adapter=new YWNNListAdapter(this,ywnns);
        lc_list.setItemProvider(adapter);
        lc_list.setItemClickedListener(new ListContainer.ItemClickedListener() {
            @Override
            public void onItemClicked(ListContainer listContainer, Component component, int i, long l) {
                intent.setParam("image",images[i]);
                intent.setParam("index",i);
                present(new YWNNDetailsAbilitySlice(), intent);
            }
        });
    }

    private void initDate() {
        for (int i = 0; i < images.length; i++) {
            YWNN ywnn=new YWNN(images[i],names[i],briefs[i]);
            ywnns.add(ywnn);
        }
    }
}
